﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Admin_Dept.aspx.cs" Inherits="Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/Resources/xiaovcn/css/ssec-form.css"/>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/common.js" ></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/usercheck.js"></script>
    <script type="text/javascript">

        function callback(res) {
            if (res.value) {
                $('#t3').combotree('reload');
                $('#tt').treegrid('reload');
                $('#add').window('close');
                $('#merge').window('close');
                $('#move').window('close');
                $.messager.alert('提示', '操作成功！');
            }
            else {
                $.messager.alert('提示', res.error.	Message);
            }
        }

        function save() {
            var a = $('#t1').val();
            var b = $('#t2').val();
            var c = $('#t3').combotree('getValue');
            var d = null;
            var e = $('#t5').val();
            Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.Save(a, b, c,d,e, callback);
        }

        function del(node) {
            Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.DeleteNode(node.ID, callback);
        }

        function clear(node) {
            Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.ClearNode(node.ID, callback);
        }

        function loadCombotree() {
            $('#t3').combotree({ url: 'Json/Dept.aspx?t=combotree' });
        }

        $(function () {
            loadCombotree();
            $('#tt').treegrid({
                title: '组织机构列表',
                url: 'Json/Dept.aspx?t=useradmin&userdept=<%=PUser.USERDEPT%>',
                iconCls: 'icon-applicationgo',
                nowrap: true,
                rownumbers: true,
                animate: false,
                collapsible: false,
                singleSelect: true,
                remoteSort: false,
                idField: 'DWBM',
                treeField: 'DWMC',
                columns: [[
                         { field: 'DWBM', title: '编码', width: 150 },
                         { field: 'DWMC', title: '名称', sortable: true, width: 200, formatter: function (val, rec) { return unescape(val) } },    
                         { field: 'XSSX', title: '排序', sortable: true, width: 150, formatter: function (val, rec) { return unescape(val) } }                         
                ]],
                toolbar: [{
                    text: '新增同级机构',
                    disabled:<%=(!this.Permissions[0].Allow).ToString().ToLower()%>,
                    iconCls: 'icon-add',
                    handler: function () {
                        clearForm();//重置表单
                        $('#t3').attr("disabled", "disabled");
                        $('#t1').removeAttr("disabled");
                        var node = $('#tt').treegrid('getSelected');
                        if (node != null) {
                            //弹出窗口
                            $('#t3').combotree('setValue', node.PARENTID);
                        }
                        $('#add').window('open');
                    }
                }, '-', {
                    text: '增加下级机构',
                    iconCls: 'icon-add', 
                    disabled:<%=(!this.Permissions[0].Allow).ToString().ToLower()%>,
                    handler: function () {
                        clearForm();//重置表单
                        $('#t3').attr("disabled", "disabled");
                        $('#t1').removeAttr("disabled");
                        var node = $('#tt').treegrid('getSelected');
                        if (node != null) {
                            //弹出窗口
                            $('#t3').combotree('setValue', node.DWBM);
                        }
                        $('#add').window('open');
                    }
                }, '-', {
                    text: '修改机构',
                    disabled:<%=(!this.Permissions[1].Allow).ToString().ToLower()%>,
                    iconCls: 'icon-edit',
                    handler: function () {
                        editrow();
                    }
                }, '-', {
                    text: '增加四级机构',
                    disabled:<%=(!this.Permissions[2].Allow).ToString().ToLower()%>,
                    iconCls: 'icon-edit',
                    handler: function () {
                        clearForm();//重置表单
                        var node = $('#tt').treegrid('getSelected');
                        
                        if (node != null && node.DWBM.length == 6) {

                            //弹出窗口
                            $('#t3').combotree('setValue', node.DWBM);                            
                            $('#t3').attr("disabled", "disabled");
                            var newsid = Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.GetNewId(node.DWBM).value;
                            $('#t1').val(newsid);
                            $('#t1').attr("disabled", "disabled");
                            $('#add').window('open');
                        }
                        else {
                            alert('请选择一个队');
                        }
                    }
                }, '-', {
                    text: '合并四级机构',
                    iconCls: 'icon-edit',
                    disabled:<%=(!this.Permissions[3].Allow).ToString().ToLower()%>,
                    handler: function () {
                        merge();
                    }
                }, '-', {
                    text: '移动四级机构',
                    iconCls: 'icon-edit',
                    disabled:<%=(!this.Permissions[4].Allow).ToString().ToLower()%>,
                    handler: function () {
                        move();
                    }
                }, '-', {
                    text: '删除机构',
                    iconCls: 'icon-remove',
                    disabled:true,
                    handler: function () {
                        var node = $('#tt').treegrid('getSelected');
                        var nodes;
                        if (node) {
                            nodes = $('#tt').treegrid('getChildren', node.DWBM);
                            if (nodes.length > 0) {
                                $.messager.confirm('提示', '当前节点还有(' + nodes.length + ')个下级机构，要一并删除吗？', function (r) {
                                    if (r) {
                                        clear(node);
                                    }
                                });
                            }
                            else {
                                $.messager.confirm('提示', '确定要删除【' + unescape(node.DWMC) + '】这个机构吗?', function (r) {
                                    if (r) {
                                        del(node);
                                    }
                                });
                            }
                        }
                        else
                            alert('请选中一个机构');
                    }
                }],
                onLoadSuccess: function () {
                    $('#mask').fadeOut('slow');
                }
            });
        });

        function editrow() {
            var node = $('#tt').treegrid('getSelected');
            if (node) {
                //修改
                $('#t1').attr('value', node.DWBM);
                $('#t1').attr("disabled", "disabled");
                $('#t2').attr('value', unescape(node.DWMC));
                $('#t3').combotree('setValue', node.PARENTID);                

                //if (node.DISABLED == "1")
                    //$('#t4').attr('checked', true);
                //else
                    //$('#t4').attr('checked', false);


                $('#t5').attr('value', node.XSSX);                
                $('#add').window('open');
            }
            else
                alert('请选中一个机构');
        }

        function merge()
        {
            $('#dw1').combotree({ url: 'Json/Dept.aspx?t=useradmincombo&userdept=<%=PUser.USERDEPT%>' });
            $('#dw2').combotree({ url: 'Json/Dept.aspx?t=useradmincombo&userdept=<%=PUser.USERDEPT%>' });
            $('#merge').window('open');
        }

        function move()
        {
            $('#dw3').combotree({ url: 'Json/Dept.aspx?t=useradmincombo&userdept=<%=PUser.USERDEPT%>' });
            $('#dw4').combotree({ url: 'Json/Dept.aspx?t=useradmincombo&userdept=<%=PUser.USERDEPT%>' });
            $('#move').window('open');
        }


        function hebing()
        {            
            var a = $('#dw1').combotree('getValue');
            var b = $('#dw2').combotree('getValue');
            Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.MergeChildNode(a, b, callback);
        }

        function yidong()
        {            
            var a = $('#dw3').combotree('getValue');
            var b = $('#dw4').combotree('getValue');
            Xiaov.SmartWeb.Application.SysAdmin.Admin_Dept.MoveChildNode(a, b, callback);
        }

</script>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">    
  <table id="tt" style="height:500px;">
    </table> 
    <script>
        $('#tt').css('height', userScreenHeight + 20);
    </script>
        <div id="add" class="easyui-window" closed="true" modal="true" maximized="false"  title="组织机构" style="width:400px; height:300px;" >
        <div id="contents" class="ssec-form">
        <div class="ssec-group ssec-group-hasicon"><img src="../Resources/easyui-1.32/themes/icons/mini_add.png" alt=""/>机构信息</div>
            <table>
            <tr>
                <td><div class="ssec-label">机构编码：</div></td>
                <td><div class="ssec-text normal"><asp:TextBox ID="t1" ClientIDMode="Static" runat="server" CssClass="ssec-text-field easyui-validatebox"  required="true"  ></asp:TextBox></div></td>             
           </tr> 
            <tr>   
                <td><div class="ssec-label">机构名称：</div></td>
                <td><div class="ssec-text normal"><asp:TextBox ID="t2" ClientIDMode="Static" runat="server" CssClass="ssec-text-field easyui-validatebox"  required="true" ></asp:TextBox></div></td>
            </tr>   
            <tr>   
                <td><div class="ssec-label">上级机构：</div></td>
                <td><div><asp:TextBox ID="t3" ClientIDMode="Static" runat="server" class="easyui-combotree"  panelHeight="300px" panelWidth="300px" Enabled="false"></asp:TextBox></div></td>
            </tr>                  
            <tr>   
                <td><div class="ssec-label">排序：</div></td>
                <td><div class="ssec-text normal"><asp:TextBox ID="t5" ClientIDMode="Static" runat="server" CssClass="ssec-text-field"></asp:TextBox></div></td>
            </tr>   
            </table>
           <div style="text-align:left; padding:5px"><a  class="easyui-linkbutton" iconCls="icon-save"  onclick="save();">保存</a></div>   
           </div>
    </div>
    <div id="merge" class="easyui-window" closed="true" modal="true" maximized="false"  title="合并站" style="width:400px; height:300px;" >
        <table>
            <tr>
                <td>将站A=></td>
                <td><asp:TextBox ID="dw1" ClientIDMode="Static" runat="server" class="easyui-combotree"  panelHeight="300px" panelWidth="300px" ></asp:TextBox></td>
          </tr>
            <tr>
                <td>并入站B=></td>
                <td><asp:TextBox ID="dw2" ClientIDMode="Static" runat="server" class="easyui-combotree"  panelHeight="300px" panelWidth="300px" ></asp:TextBox></td>               
            </tr>
            <tr>
                <td></td>
                <td><a  class="easyui-linkbutton" iconCls="icon-save"  onclick="if(confirm('确定要合并吗?这个操作不能撤销！请谨慎操作，一旦开始站1的单井信息将并入站2，站1将被移除!')){ hebing();}">合并成站B</a></td>
            </tr>
            <tr>
                <td></td>
                <td>注：合并之后的新站点将包含两个站的所有单井信息，<br/>并且：站A将被删除</td>
            </tr>
        </table>
    </div>

       <div id="move" class="easyui-window" closed="true" modal="true" maximized="false"  title="移动站" style="width:400px; height:300px;" >
        <table>
            <tr>
                <td>将四级单位=></td>
                <td><asp:TextBox ID="dw3" ClientIDMode="Static" runat="server" class="easyui-combotree"  panelHeight="300px" panelWidth="300px" ></asp:TextBox></td>
          </tr>
            <tr>
                <td>移到三级单位下=></td>
                <td><asp:TextBox ID="dw4" ClientIDMode="Static" runat="server" class="easyui-combotree"  panelHeight="300px" panelWidth="300px" ></asp:TextBox></td>               
            </tr>
            <tr>
                <td></td>
                <td><a  class="easyui-linkbutton" iconCls="icon-save"  onclick="if(confirm('确定要移动吗?')){ yidong();}">移动</a></td>
            </tr>
        </table>
    </div>
</asp:Content>
